<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用支付宝</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script>
    var water_info = <?php echo json_encode($water_info); ?> ;
    getDeviceOnline()
    // console.log('打开小程序成功', water_info);
    function getDeviceOnline() {
        $.ajax({
            url: 'https://grzq.wajx.top/api/apicrzs/intake/device/online',
            method: 'GET',
            data: {
                fee_id: water_info.id,
            },
            success: function (res) {
                if (res.data.check === true) {
                    getEquipmentOnline()
                } else {
                    alert(res.data.msg)
                }
            },
            error: function (error) {
                alert('扫码失败！')
            }
        });
    }
    function getEquipmentOnline(){
        $.ajax({
            url: 'https://grzq.wajx.top/api/apicrzs/intake/order/create',
            method: 'POST',
            data:{
                type: 'consume',
                fee_id: water_info.id,
                pay_type: 'alipay'
            },
            success: function(res) {
                if(res.status === 0){
                    alipayFun(res.data.data)
                }
                alert('success' + JSON.stringify(data))
            },
            error: function(error) {
                alert('扫码失败！')
            }
        });
    }
    function alipayFun(obj){
        console.log('dayin',obj.order_sn)
        $.ajax({
            url: 'https://grzq.wajx.top/api/apicrzs/intake/order/payment',
            method: 'POST',
            data:{
                order_sn:obj.order_sn,
                openid:obj.openid
            },
            success: function(res) {
                var resData =res.data
                if(res.status === 0){
                    const div = document.createElement('div')
                    div.id = 'alipay'
                    div.innerHTML = resData
                    document.body.appendChild(div)
                    document.querySelector('#alipay').children[0].submit()
                    // alert("扫码成功，正在打水中...")
                }
            },
            error: function(error) {
                console.error('Error:', error);
                alert('扫码失败！')
            }
        });
    }
</script>
</body>
